/*
 * Copyright (C) 2012 Le Tuan Anh <anh.takaji@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ezcms.dal.hibernate.mysql;

import ezcms.dal.ConferenceItemDAO;
import ezcms.dto.ConferenceItem;
import ezcms.dto.ConferenceItemType;
import ezcms.dto.PresentationType;
import ezcms.exceptions.DataLayerException;
import java.util.List;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Le Tuan Anh <anh.takaji@gmail.com>
 */
class ConferenceItemDAOImpl implements ConferenceItemDAO {

    public ConferenceItemDAOImpl() {
    }

    @Override
    public List<ConferenceItem> getAllConferenceItems() throws DataLayerException {
        return HibernateUtil.getListByConditions(ConferenceItem.class, null, "Cannot retrieve all ConferenceItems");
    }

    @Override
    public ConferenceItem getConferenceItemById(long id) throws DataLayerException {
        Object result = HibernateUtil.getObjectById(ConferenceItem.class, id, "Cannot find ConferenceItem object with id = " + id);
        return (result == null) ? null : (ConferenceItem) result;
    }

    @Override
    public void saveConferenceItem(ConferenceItem conferenceItem) throws DataLayerException {
        HibernateUtil.saveObject(conferenceItem, "Cannot save ConferenceItem");
    }

    @Override
    public void deleteConferenceItem(ConferenceItem conferenceItem) throws DataLayerException {
        HibernateUtil.deleteObject(conferenceItem, "Cannot delete ConferenceItem");
    }

    @Override
    public List<ConferenceItemType> getAllConferenceItemTypes() throws DataLayerException {
        return HibernateUtil.getListByConditions(ConferenceItemType.class, null, "Cannot retrieve all ConferenceItemTypes");
    }

    @Override
    public ConferenceItemType getConferenceItemTypeById(long id) throws DataLayerException {
        Object result = HibernateUtil.getObjectById(ConferenceItemType.class, id, "Cannot find ConferenceItemType object with id = " + id);
        return (result == null) ? null : (ConferenceItemType) result;
    }

    @Override
    public void saveConferenceItemType(ConferenceItemType conferenceItemType) throws DataLayerException {
        HibernateUtil.saveObject(conferenceItemType, "Cannot save ConferenceItemType");
    }

    @Override
    public void deleteConferenceItemType(ConferenceItemType conferenceItemType) throws DataLayerException {
        HibernateUtil.deleteObject(conferenceItemType, "Cannot delete ConferenceItemType");
    }

    @Override
    public List<PresentationType> getAllPresentationTypes() throws DataLayerException {
        return HibernateUtil.getListByConditions(PresentationType.class, null, "Cannot retrieve all PresentationTypes");
    }

    @Override
    public PresentationType getPresentationTypeById(long id) throws DataLayerException {
        Object result = HibernateUtil.getObjectById(PresentationType.class, id, "Cannot find PresentationType object with id = " + id);
        return (result == null) ? null : (PresentationType) result;
    }

    @Override
    public void savePresentationType(PresentationType presentationType) throws DataLayerException {
        HibernateUtil.saveObject(presentationType, "Cannot save PresentationType");
    }

    @Override
    public void deletePresentationType(PresentationType presentationType) throws DataLayerException {
        HibernateUtil.deleteObject(presentationType, "Cannot delete PresentationType");
    }

    @Override
    public ConferenceItemType getConferenceItemTypeByTitle(String title) throws DataLayerException {
        Object result = HibernateUtil.getObjectByConditions(ConferenceItemType.class, Restrictions.eq("title", title), "Cannot retrieve itemType with title = " + title);
        return (result == null) ? null : (ConferenceItemType) result;
    }

    @Override
    public PresentationType getPresentationTypeByTitle(String title) throws DataLayerException {
        Object result = HibernateUtil.getObjectByConditions(PresentationType.class, Restrictions.eq("title", title), "Cannot retrieve presentationType with title = " + title);
        return (result == null) ? null : (PresentationType) result;
    }
}
